package com.nciae.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.nciae.chain.SecurityQuestionChain;
import com.nciae.po.SecurityQuestion;
import com.nciae.dao.SecurityQuestionMapper;
import com.nciae.service.ISecurityQuestionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Guoliyu
 * @since 2022-03-30
 */
@Service
public class SecurityQuestionServiceImpl extends ServiceImpl<SecurityQuestionMapper, SecurityQuestion> implements ISecurityQuestionService {

    @Autowired
    private SecurityQuestionChain securityQuestionChain;


    @Override
    public void add(SecurityQuestion securityQuestion) {
        securityQuestion.setSubmitTime(new Date())
        ;
        baseMapper.insert(securityQuestion);
    }


    @Override
    public List<SecurityQuestion> findByDormitoryId(Long id) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("dormitory_id", id);
        List<SecurityQuestion> securityQuestions = baseMapper.selectList(wrapper);
        for(SecurityQuestion securityQuestion : securityQuestions) {
            securityQuestionChain.service(securityQuestion, 2);
        }
        return securityQuestions;
    }

    @Override
    public List<SecurityQuestion> selectList(QueryWrapper wrapper) {
        return baseMapper.selectList(wrapper);
    }
}
